﻿using Model;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZBZH_Manage_Order.Models;
using ZBZH_Manage_Order.PublicMethod;

namespace ZBZH_Manage_Order.Controllers.MerchantsSettings
{
    public class AddressManagementController : Controller
    {
        //
        // GET: /AddressManagement/
        ServiceReference1.Service1Client wsdcser = new ServiceReference1.Service1Client();  

        public ActionResult Index()
        {
            return View();
        }

        #region 所有地址
        public ActionResult getAdderss(JqGridParam jqgridparam)
        {
            try
            {
                List<Model.Order_MerSendAdd_T> list_ot = new List<Model.Order_MerSendAdd_T>();
                string result = wsdcser.GetAllMerSendAdd(jqgridparam.page, jqgridparam.rows, GetYZM._YZM, 1);
                JObject searcho = JObject.Parse(result);
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    IList<JToken> jieguo = searcho["rows"].Children().ToList();
                    if (jieguo.Count > 0)
                    {
                        list_ot = ParseClass<Model.Order_MerSendAdd_T>.JsonList(jieguo);
                    }
                    var data = new
                    {
                        total = searcho["total"].ToString(),
                        rows = list_ot
                    };
                    return Json(list_ot);
                }
                else
                {
                    var data = new
                    {
                        total = "0",
                        rows = list_ot
                    };
                    return Json(list_ot);
                }
            }
            catch (Exception ex)
            {
                return Content("系统异常" + ex);
            }
        }
        #endregion

        #region 更新地址
        public ActionResult Updata(Order_MerSendAdd_T Adderss, int Tag)
        {
            try
            {
                Order_MerSendAdd_T adder = new Order_MerSendAdd_T();
                adder.AddId = Adderss.AddId;
                adder.AddName = Adderss.AddName;
                adder.AddStat = 1;
                adder.ToJson();
                //string zzz = adder.ToJson();
                string result = wsdcser.SetOrder_MerSendAdd(adder.ToJson(), Tag, GetYZM._YZM, 1);
                JObject searcho = JObject.Parse(result);
                string bs = searcho["BS"].ToString();
                if (bs == "1")
                {
                    return Content("ok");
                }
                else
                {
                    return Content("失败");
                }

            }
            catch (Exception ex)
            {
                return Content("系统异常" + ex);
            }
        }
        #endregion

    }
}
